package user;

// 这个单例类用于存储已登录用户的基本信息供全局使用
public class UserInfo {

    private volatile static UserInfo userInfo;
    private String username;
    private int userId;

    private UserInfo() {}

    /**双重锁定检查
     */
    public static UserInfo getInstance(){
        if(userInfo == null){
            synchronized (UserInfo.class){
                if(userInfo == null){
                    userInfo = new UserInfo();
                }
            }
        }
        return userInfo;
    }

    public void setUsername(String username){ this.username = username; }

    public String getUsername() { return this.username; }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public int getUserId() {
        return userId;
    }
}
